package com.ruoyi.lease.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.filter.ID;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.lease.domain.AtbLabelLog;
import com.ruoyi.lease.domain.AtbLeaseHouse;
import com.ruoyi.lease.dto.request.StatusDto;
import com.ruoyi.lease.dto.respond.AtbHouseDto;
import com.ruoyi.lease.mapper.AtbLabelLogMapper;
import com.ruoyi.lease.mapper.AtbLeaseHouseMapper;
import com.ruoyi.lease.service.IAtbLeaseHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 租房审核Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-09-16
 */
@Service
public class AtbLeaseHouseServiceImpl implements IAtbLeaseHouseService
{
    @Autowired
    private AtbLeaseHouseMapper atbLeaseHouseMapper;

    @Autowired
    private AtbLabelLogMapper atbLabelLogMapper;

    /**
     * 查询租房审核
     * 
     * @param id 租房审核主键
     * @return 租房审核
     */
    @Override
    public AtbHouseDto selectAtbHouseById(Long id)
    {
        AtbHouseDto atbHouse = atbLeaseHouseMapper.selectAtbHouseById(id);
        atbHouse.setLabelList(atbLeaseHouseMapper.selectLabelById(atbHouse.getId()));

        return atbHouse;
    }

    /**
     * 查询租房审核列表
     *
     * @param atbLeaseHouse 租房审核
     * @return 租房审核
     */
    @Override
    public List<AtbHouseDto> selectAtbHouseList(AtbLeaseHouse atbLeaseHouse)
    {
        List<AtbHouseDto> atbHouseDtos = atbLeaseHouseMapper.selectAtbHouseList(atbLeaseHouse);
        for (AtbHouseDto atbHouseDto : atbHouseDtos) {
            List<String> selectLabelById = atbLeaseHouseMapper.selectLabelById(atbHouseDto.getId());
            atbHouseDto.setLabelList(selectLabelById);
        }
        return atbHouseDtos;
    }

    /**
     * 新增租房审核
     * 
     * @param atbLeaseHouse 租房审核
     * @return 结果
     */
    @Override
    public int insertAtbHouse(AtbLeaseHouse atbLeaseHouse)
    {
        atbLeaseHouse.setId(new ID().getId());
        atbLeaseHouse.setCreateTime(DateUtils.getNowDate());
        return atbLeaseHouseMapper.insertAtbHouse(atbLeaseHouse);
    }

    /**
     * 修改租房审核
     * 
     * @param atbLeaseHouse 租房审核
     * @return 结果
     */
    @Override
    public int updateAtbHouse(AtbLeaseHouse atbLeaseHouse)
    {
        System.out.println(atbLeaseHouse);
//        QueryWrapper<AtbLabelLog> atbLabelLogQueryWrapper = new QueryWrapper<>();
//        atbLabelLogQueryWrapper.lambda().eq(AtbLabelLog::getObjectId,atbLeaseHouse.getId());
//        atbLabelLogMapper.delete(atbLabelLogQueryWrapper);
        return atbLeaseHouseMapper.updateAtbHouse(atbLeaseHouse);
    }

    /**
     * 批量删除租房审核
     * 
     * @param ids 需要删除的租房审核主键
     * @return 结果
     */
    @Override
    public int deleteAtbHouseByIds(Long[] ids)
    {
        return atbLeaseHouseMapper.deleteAtbHouseByIds(ids);
    }

    /**
     * 删除租房审核信息
     * 
     * @param id 租房审核主键
     * @return 结果
     */
    @Override
    public int deleteAtbHouseById(Long id)
    {
        return atbLeaseHouseMapper.deleteAtbHouseById(id);
    }

    @Override
    public int updateStatus(StatusDto statusDto) {
        if (statusDto.getMes().equals("审核")) {
      //      atbLeaseHouseMapper.updateAtbHouseDetailExamineStatus(statusDto);
            return atbLeaseHouseMapper.updateExamineStatus(statusDto);
        }

        if (statusDto.getMes().equals("上下架")) {
   //         atbLeaseHouseMapper.updateAtbHouseDetailPutawayStatus(statusDto);
            return atbLeaseHouseMapper.updatePutawayStatus(statusDto);
        }

        return -1;
    }
}
